import { getFile } from "@/services/public";
import moment from "moment";

const fileDownload = (url:string) => {
    getFile(url).then((res)=>{
        const nowTime = moment().format('YYYYMMDDHHmm');
        const blob = new Blob([res]);
        const objectURL = URL.createObjectURL(blob);
        const btn = document.createElement('a');
        const body = document.querySelector('body');
        if (body) {
          body.appendChild(btn);
        }
        btn.download = '123';
        btn.target = "downloadFile";
        btn.href = objectURL;
        btn.click();
        if (body) {
          body.removeChild(btn); // 删除标签
        }
    })
}

export default fileDownload;